package client.comm.baoding.fragment

import android.content.Intent
import android.widget.*
import androidx.core.view.ViewCompat
import client.comm.baoding.R
import client.comm.baoding.adapter.main.HomePageAdapter
import client.comm.baoding.databinding.FragmentTabnewBinding
import client.comm.baoding.ui.SearchActivity
import client.comm.baoding.ui.vm.MainViewModel
import client.comm.commlib.base.BaseFragment
import client.comm.commlib.utils.Util

class TabNewFragment : BaseFragment<FragmentTabnewBinding, MainViewModel>() {

    override fun getViewId(): Int {
        return R.layout.fragment_tabnew
    }

    override fun initViewModel(): MainViewModel = createViewModel()

    override fun initWidget() {
        binding.statusBar.post {
            val h = Util.getStatusBarHeight(requireContext())
            val p = binding.statusBar.layoutParams
            p.height = h
            binding.statusBar.layoutParams = p
            Util.setBg(resources!!.getColor(R.color.main_color), requireActivity().window)
            val controller = ViewCompat.getWindowInsetsController(binding.root)
            controller?.isAppearanceLightStatusBars = true
        }
        binding.apply {
            event = this@TabNewFragment
            viewPager.adapter = adapter
            tabLayout.setupWithViewPager(viewPager)
        }
    }

    val adapter: HomePageAdapter by lazy {
        HomePageAdapter(childFragmentManager)
    }

    fun goSearch() {
        startActivity(Intent(requireContext(), SearchActivity::class.java))
    }


}